package com.exampletest;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import java.io.IOException;

@SpringBootApplication
@MapperScan("com.exampletest.mapper")
@ComponentScan(basePackages = {"com.exampletest", "com.exampletest.service"})
public class Application {
    public static void main(String[] args) throws IOException {
        SpringApplication.run(Application.class, args);
        // 启动后自动打开浏览器访问首页




            String url = "http://localhost:8080/";
            try {
                openBrowser(url);
            } catch (Exception e) {
                System.err.println("无法打开浏览器，请手动访问: " + url);
            }
        }

        private static void openBrowser(String url) throws IOException {
            String os = System.getProperty("os.name").toLowerCase();
            Runtime runtime = Runtime.getRuntime();

            if (os.contains("win")) {
                // Windows
                runtime.exec("cmd /c start " + url);
            } else if (os.contains("mac")) {
                // macOS
                runtime.exec("open " + url);
            } else if (os.contains("nix") || os.contains("nux")) {
                // Linux/Unix
                runtime.exec("xdg-open " + url);
            } else {
                throw new UnsupportedOperationException("不支持的操作系统");
            }
        }

} 